package cn.yunhe.action;

import cn.yunhe.modle.Member;
import cn.yunhe.modle.Pagination;
import cn.yunhe.service.MemberBiz;
import cn.yunhe.util.BaseActionUtil;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*Spring注解*/
/*@Controller(value = "memberAction")*/
public class MemberAction extends BaseActionUtil implements ModelDriven {

    /*Spring注解*/
    @Autowired
    @Qualifier(value = "memberBiz")
    private MemberBiz memberBiz;//service层

    private Member member;//模型驱动
    private Integer currPageNo;//属性驱动
    private Integer maxRows;//属性驱动

    private Pagination<Member>pagination=new Pagination<>();//json的返回值数据类型


    public String searchMemberByConditions(){
        Map<String,Object>objectMap=new HashMap<>();
        //多条件筛选的入参
        objectMap.put("mname",member.getMname());
        //获取多条件筛选的总记录数(统计)
        Integer totalRecords=memberBiz.searchByConditions2TotalRecords(objectMap);
        //多条件筛选的集合(分页)
        objectMap.put("currPageNo",currPageNo);
        objectMap.put("maxRows",maxRows);
        List<Member>memberList=memberBiz.searchByConditions(objectMap);

        //分页三要素
        pagination.setTotalRecords(totalRecords);
        pagination.setCurrPageNo(currPageNo);
        pagination.setMaxRows(maxRows);
        pagination.setList(memberList);
        return SUCCESS;
    }


    public MemberBiz getMemberBiz() {
        return memberBiz;
    }

    public void setMemberBiz(MemberBiz memberBiz) {
        this.memberBiz = memberBiz;
    }

    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    public Integer getCurrPageNo() {
        return currPageNo;
    }

    public void setCurrPageNo(Integer currPageNo) {
        this.currPageNo = currPageNo;
    }

    public Integer getMaxRows() {
        return maxRows;
    }

    public void setMaxRows(Integer maxRows) {
        this.maxRows = maxRows;
    }

    public Pagination<Member> getPagination() {
        return pagination;
    }

    public void setPagination(Pagination<Member> pagination) {
        this.pagination = pagination;
    }

    @Override
    public Member getModel() {
        if (member==null)
            member=new Member();
        return member;
    }
}
